#!/usr/bin/python
# -*- coding:utf-8 -*-
# @FileName : Xxhg_ShiXian.py
# Author    : myh
import torch
from d2l import torch as d2l


def synthetic_data(w, b, num_len):
    x = torch.normal(1, 2, (num_len, len(w)))
    y = torch.matmul(x, w) + b
    # 增加噪声
    erro_y = torch.normal(0, 0.01, y.shape)
    y = y + erro_y
    return x, y


w = torch.tensor([2, -3.4])
b = 4.2
features, labels = synthetic_data(w, b, 1000)

# print(features)
# print(labels)
d2l.plt.figure(1)
d2l.plt.scatter(features[:,1], labels, 1)
d2l.plt.show()
d2l.plt.figure(2)
d2l.plt.scatter(features[:,0], labels, 1)
d2l.plt.show()



